package com.example.uiframework.utils;

import android.content.res.Resources;
import android.graphics.Color;
import android.util.TypedValue;

public class ResUtils {
    public float dpF(float value) {
        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, Resources.getSystem().getDisplayMetrics());
    }
    public int dpI(float value) {
        return (int) dpF(value);
    }

    public int getColor(float progress, int startColor, int endColor) {
        int redStart = Color.red(startColor);
        int blueStart = Color.blue(startColor);
        int greenStart = Color.green(startColor);
        int alphaStart = Color.alpha(startColor);
        int redEnd = Color.red(endColor);
        int blueEnd = Color.blue(endColor);
        int greenEnd = Color.green(endColor);
        int alphaEnd = Color.alpha(endColor);
        int redDifference = redEnd - redStart;
        int blueDifference = blueEnd - blueStart;
        int greenDifference = greenEnd - greenStart;
        int alphaDifference = alphaEnd - alphaStart;

        int redCurrent = (int) (redStart + progress * redDifference);
        int blueCurrent = (int) (blueStart + progress * blueDifference);
        int greenCurrent = (int) (greenStart + progress * greenDifference);
        int alphaCurrent = (int) (alphaStart + progress * alphaDifference);
        return Color.argb(alphaCurrent, redCurrent, greenCurrent, blueCurrent);

    }
}
